
function strict(str) {
    if (isObject(str)) {
        return true;
    }

    try {
        return JSON.parse(str) && true;
    } catch (ex) {
        return false;
    }
}
function getAllKeys(obj, parentKey = '', result = []) {
    for (let key in obj) {
        if (obj.hasOwnProperty(key)) {
            const fullKey = parentKey ? `${parentKey}.${key}` : key;
            result.push(fullKey);
            if (typeof obj[key] === 'object' && obj[key] !== null && !Array.isArray(obj[key])) {
                getAllKeys(obj[key], fullKey, result);
            }
        }
    }
    return result;
}
function isString(x) {
    return Object.prototype.toString.call(x) === '[object String]';
}

function isObject(obj) {
    return Object.prototype.toString.call(obj) === '[object Object]';
}
module.exports = {
    replaceHomePath(path, homeDirPath) {
        // 检查路径中是否包含<HOMEPATH>  
        if (path.includes('<HOMEPATH>')) {
            // 使用指定的主目录路径替换<HOMEPATH>  
            return path.replace('<HOMEPATH>', homeDirPath);
        }
        // 如果没有包含<HOMEPATH>，则返回原始路径  
        return path;
    },


    areKeysEqual(obj1, obj2) {
        try {
            if (Buffer.isBuffer(obj2)) { //
                obj2 = JSON.parse(String(obj2));
            }
            // 创建一个Set来存储obj1的键  
            const keys1 = getAllKeys(obj1);
            // 创建一个Set来存储obj2的键  
            const keys2 = getAllKeys(obj2);
            if (keys1.length !== keys2.length) {
                return false;
            }


            // 如果通过了所有检查，说明两个对象的键完全相同  
            return true;
        } catch (e) {
            return false;
        }

    },
    isJson: (str) => {
        if (typeof str == 'string') {
            try {
                JSON.parse(str);
                return true;
            } catch (e) {
                console.log(e);
                return false;
            }
        } else {
            return false;
        }
    }, debounce(fn, delay) {
        let timeoutID;
        return function (...args) {
            clearTimeout(timeoutID);
            timeoutID = setTimeout(() => {
                fn.apply(this, args);
            }, delay);
        }
    }




}